package sz.szsmk.citizencard.ui.activity;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.annotation.RequiresApi;

import com.chenenyu.router.annotation.Route;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.ui.base.IBaseActivity;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/30 15:56
 * description:
 */
@Route("orderactivity")
public class OrderActivity extends IBaseActivity implements View.OnClickListener {

    View line1;
    LinearLayout btn1;
    View line2;
    LinearLayout btn2;
    View line3;
    LinearLayout btn3;
    View line4;
    LinearLayout btn4;
    View line5;
    LinearLayout btn5;


    private WebView wv_content;
    private ProgressBar mProgress;
    private String url;
    private ImageView ivBack;

    @Override
    protected int attachLayoutRes() {
        return R.layout.order_activity;
    }

    @Override
    protected void initInjector() {

    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @SuppressLint("JavascriptInterface")
    @Override
    protected void initViews() {

        line1 = findViewById(R.id.line1);
        btn1= findViewById(R.id.btn1);
        line2= findViewById(R.id.line2);
        btn2= findViewById(R.id.btn2);
        line3= findViewById(R.id.line3);
        btn3= findViewById(R.id.btn3);
        line4= findViewById(R.id.line4);
        btn4= findViewById(R.id.btn4);
        line5= findViewById(R.id.line5);
        btn5= findViewById(R.id.btn5);





        wv_content = (WebView) findViewById(R.id.order_web);
        mProgress = (ProgressBar) findViewById(R.id.web_progress);
//        https://newapptest.szsmk.com/app-front-end/#/myOrder/all?page_type=2
        url = "https://newapptest.szsmk.com/app-front-end/#/myOrder/all?page_type=2";
//        url = getIntent().getStringExtra("url");
        ivBack = (ImageView) findViewById(R.id.back);
        ivBack.setOnClickListener(this);
        wv_content.getSettings().setJavaScriptEnabled(true);
        wv_content.getSettings().setDomStorageEnabled(true);
        wv_content.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);
        String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath();
        wv_content.getSettings().setAppCachePath(appCachePath);
        wv_content.getSettings().setAllowFileAccess(true);
        wv_content.getSettings().setAppCacheEnabled(true);
//        wv_content.addJavascriptInterface(new PureTextWebViewActivity.JsInteration(), "android");

        wv_content.setWebViewClient(new WebViewClient());
        //设置加载进度条
        wv_content.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {

                if (newProgress == 100) {
                    mProgress.setVisibility(View.GONE);//加载完网页进度条消失
                } else {
                    mProgress.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
                    mProgress.setProgress(newProgress);//设置进度值
                }
            }
        });

        wv_content.loadUrl(url);
        wv_content.reload();
    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.back) {
            finish();
        } else if (id == R.id.btn1) {
            Toast.makeText(this, "全部", Toast.LENGTH_SHORT).show();
            url = "https://newapptest.szsmk.com/app-front-end/#/myOrder/all?page_type=3";
            wv_content.loadUrl(url);
            wv_content.reload();
        } else if (id == R.id.btn2) {
        } else if (id == R.id.btn3) {
        } else if (id == R.id.btn4) {
        } else if (id == R.id.btn5) {
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}
